package sebastiankerckhof.scene.material;

import sebastiankerckhof.math.Color3f;
import sebastiankerckhof.math.Vector3f;
import sebastiankerckhof.render.raytrace.Ray;
import sebastiankerckhof.render.raytrace.Hit.Hit;

public class PhongMaterial extends AbstractMaterial{
	public float shininess;
	
	public PhongMaterial(Color3f color, float shininess) {
		super(color);
		this.shininess = shininess;
	}
	
	@Override
	public Color3f getShade(Color3f t, Color3f cl, Vector3f l, Vector3f n, Ray r) {
		Color3f result;
		
		Vector3f h = r.direction.scale(-1).add(l).normalize(); // (v+l)/||v+l||
		float dot = h.dotProduct(n); // n.h
		dot = (float) Math.pow(Math.max(0, -dot), shininess); //max(0,n.h)^p
		
		result = new Color3f(this.color.multiply(cl).scale(dot)); //ks.I.max(0,n.h)^p
		
		return result.clamp(); //TODO: we need to clamp here?
	}
}
